package com.team.twitter.client.web;

import java.util.List;

import org.springframework.social.twitter.api.Tweet;
import org.springframework.social.twitter.api.Twitter;
import org.springframework.social.twitter.api.impl.TwitterTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Simple just a testing controller for the moment
 * @author erdem
 *
 */
@Controller
public class MainController {
	//TODO To be handled by an external class and using keys from application.properties
	private String twitterConsumerKey = "YuUXgihU4AqOLAjL3tcw";
	private String twitterConsumerSecret = "1C6kQc0Jh7KkypX3N6rMU3gGmymVfn8VKuVSjop20";

	@RequestMapping("/")
	public String handleMain(Model model){
		return "home";
	}
	
	@RequestMapping("/search")
	public String handleSearch(@RequestParam(value="screenName") String screenName, Model model){
		Twitter twitter = new TwitterTemplate();
		List<Tweet> tweetList = twitter.timelineOperations().getUserTimeline(screenName);
		
		model.addAttribute("tweets", tweetList);
		return "home";
	}
}
